<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // websockt原生代码使用方法
        // 创建实例对象
        var ws = new WebSocket("wss://javascript.info/article/websocket/demo/hello");

        // 连接成功事件
        ws.onopen = function (evt) {
            console.log("Connection open ...");
            ws.send("Hello WebSockets!");
        };
        ws.onmessage = function (evt) {
            console.log("Received Message: " + evt.data);
            ws.close();
        };
        ws.onclose = function (evt) {
            console.log("Connection closed.");
        };      
    </script>
</body>

</html>